//操作成功后，的提示信息
function successToShow(msg = '保存成功', callback = function() {}) {
	setTimeout(function() {
		uni.showToast({
			title: msg,
			icon: 'success',
			duration: 2000,
			success() {
				setTimeout(function() {
					callback()
				}, 2000)
			}
		})
	}, 100)
}
//操作失败的提示信息
function errorToShow(msg = '操作失败', callback = function() {}) {
	setTimeout(function() {
		uni.showToast({
			title: msg,
			icon: 'none',
			duration: 2000,
			success() {
				setTimeout(function() {
					callback()
				}, 2500)
			}
		})
	}, 100)
}
//加载显示
function loadToShow(msg = '加载中') {
	uni.showToast({
		title: msg,
		icon: 'loading'
	})
}
/**
 * 页面跳转
 * @param {Object} url
 */
function navigateTo(url) {
	uni.navigateTo({
		url: url,
		animationType: 'pop-in',
		animationDuration: 300
	})
}

/**
 * App 分享
 */
function appShare(title, imageUrl, path, callback) {
	uni.share({
		provider: "weixin",
		scene: "WXSceneSession",
		type: 5,
		title: title,
		imageUrl: imageUrl, // 分享时小于20Kb的图片
		miniProgram: {
			id: 'gh_d7b19d14af01', //gh_13aacba97ced
			path: path,
			type: 0,
			webUrl: 'https://ryz1620.com'
		},
		success: function(res) {
			callback('success');
		},
		fail: function(err) {
			console.log(err);
		}
	});
}

/**
 * 时间戳格式化秒
 * @param {Object} value
 */
function formatDate(value) {
	let date = new Date(parseInt(value) * 1000);
	let y = date.getFullYear();
	let m = date.getMonth() + 1;
	m = m < 10 ? "0" + m : m;
	let d = date.getDate();
	d = d < 10 ? "0" + d : d;
	let h = date.getHours();
	h = h < 10 ? "0" + h : h;
	let minute = date.getMinutes();
	let second = date.getSeconds();
	minute = minute < 10 ? "0" + minute : minute;
	second = second < 10 ? "0" + second : second;
	return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
}
/**
 * 格式化日期
 * @param {Object} value 时间戳
 */
function timestampDate(value) {
	let date = new Date(parseInt(value) * 1000);
	let y = date.getFullYear();
	let m = date.getMonth() + 1;
	m = m < 10 ? "0" + m : m;
	let d = date.getDate();
	d = d < 10 ? "0" + d : d;
	let h = date.getHours();
	h = h < 10 ? "0" + h : h;
	let minute = date.getMinutes();
	let second = date.getSeconds();
	minute = minute < 10 ? "0" + minute : minute;
	second = second < 10 ? "0" + second : second;
	return y + "-" + m + "-" + d;
}
/**
 * 手机号4位截取
 * @param {Object} tel 手机号
 */
 function hideTel(tel) {
	 return tel.substring(0, 3)+"****"+tel.substr(tel.length-4);
}

/**
 * 时间间隔天数
 * @param {Object} start_date 开始日期
 * @param {Object} end_date 结束日期
 */
function getRemainderTime(start_date, end_date) {
	var startDate = Date.parse(start_date);
	var endDate = Date.parse(end_date);
	var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000);
	return days;
}

export {
	successToShow,
	errorToShow,
	loadToShow,
	appShare,
	navigateTo,
	formatDate,
	getRemainderTime,
	timestampDate,
	hideTel
}
